class Solution:
    pre = None

    def check_bst(self, root):
        def dfs(node):
            if not node:
                return True
            if not dfs(node.left):
                return False
            if self.pre and node.val < self.pre:
                return False
            self.pre = node.val
            if not dfs(node.right):
                return False
            return True

        return dfs(root)


from instance import Bst, AllRightBst, AllLeftBst,Tree1
solution = Solution()
print(solution.check_bst(Bst.bst))
solution2 = Solution()
print(solution2.check_bst(AllLeftBst.all_left_bst))
solution3 = Solution()
print(solution3.check_bst(AllRightBst.all_right_bst))
solution4 = Solution()
print(solution4.check_bst(Tree1.tree1))
